package com.woniuxy.threeprojcet.end_water_project_admin.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniuxy.threeprojcet.end_water_project_admin.domain.form.MeterReadingForm;
import com.woniuxy.threeprojcet.end_water_project_admin.service.impl.MeterReadingServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 水量表 前端控制器
 * </p>
 *
 * @author Lucas
 * @since 2021-08-26
 */
@RestController
@RequestMapping("/admin")
@CrossOrigin("*")
@Slf4j
public class MeterReadingController {

    @Resource
    private MeterReadingServiceImpl meterReadingService;

    @PostMapping("addMeterReading")
    public boolean addMeterReading(@RequestBody MeterReadingForm meterreadingForm){
        log.info("meterReadingForm:{}",meterreadingForm);
        int i = meterReadingService.addMeterReading(meterreadingForm);
        return i>0? true :false;
    }

    //获得用水表
    @GetMapping("getMeterReading")
    public IPage getMeterReading( @RequestParam(name = "pageSize", defaultValue = "6") int pageSize,
                                 @RequestParam(name = "current", defaultValue = "1") int current){

        IPage page = new Page(current, pageSize);

        IPage meterReading = meterReadingService.getMeterReading(page);


        return meterReading;
    }

//    //获得上一次的抄表的时间
//    public Date lastMeterTimeByWaterMeterId(String waterMeterId){
//        Date date = meterReadingService.lastMeterTimeByWaterMeterId(waterMeterId);
//        return date;
//    }



    //查询用水表
    @GetMapping("searchMeterReading")
    public IPage searchMeterReading(String waterMeterId,
            @RequestParam(name = "pageSize", defaultValue = "6") int pageSize,
                                  @RequestParam(name = "current", defaultValue = "1") int current){

        IPage page = new Page(current, pageSize);

        IPage meterReading = meterReadingService.searchMeterReading(page,waterMeterId);


        return meterReading;
    }

}

